package com.konne.nightmare.FastPublicOpinion.ui.information.activity;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.SpanUtils;
import com.konne.nightmare.FastPublicOpinion.R;
import com.konne.nightmare.FastPublicOpinion.base.BaseMvpActivity;
import com.konne.nightmare.FastPublicOpinion.base.BaseMvpPresenter;
import com.konne.nightmare.FastPublicOpinion.ui.dialog.AnnouncedTimeDialog;
import com.konne.nightmare.FastPublicOpinion.ui.dialog.SheetDialog;
import com.konne.nightmare.FastPublicOpinion.utils.LoadProgressDialog;
import com.konne.nightmare.FastPublicOpinion.utils.ToastUtil;
import com.konne.nightmare.FastPublicOpinion.widget.QJCheckBox;
import com.konne.nightmare.FastPublicOpinion.widget.QJItemTitleView;

import butterknife.BindView;

/**
 * Create by ws.
 * on Data:2022/2/13  Time:下午 1:41.
 * description: 考试设置 .
 */
public class ExamSettingAct extends BaseMvpActivity implements View.OnClickListener {
    @BindView(R.id.tv_s_num)
    TextView tv_s_num;
    private int sNum = 1;

    public static void start() {
        ActivityUtils.startActivity(ExamSettingAct.class);
    }

    @Override
    protected BaseMvpPresenter createPresenter() {
        return new BaseMvpPresenter();
    }

    @Override
    public int getLayout() {
        return R.layout.act_exam_setting;
    }

    @Override
    public void initView() {
        BarUtils.transparentStatusBar(this);
        BarUtils.setStatusBarLightMode(this, true);
        SpanUtils.with(findViewById(R.id.stv_note))
                .append("当学生在当前设备上，每离开一次答题界面，将给予提示，如果切换页面超出上限后将被强制交卷。\n\n")
                .append("注：设置次数时请考虑设备及网络等异常情况\n" +
                        "例如：手机端会存在电话呼入，电脑端广告弹框，不小心无操作\n" +
                        "切出等；\n" +
                        "特别注意：1.电脑端作答文件题时，上传图片算作1次切屏；\n" +
                        "2.手机端由于不同的操作系统，会导致切换到手机桌面，其他应\n" +
                        "用或者文件题上传图片时会每5秒记一次切屏。")
                .setForegroundColor(0xff1C2B33).create();
        SpanUtils.with(findViewById(R.id.stv_all_note))
                .append("建议学生使用")
                .append("火狐或谷歌浏览器")
                .setForegroundColor(0xff3D92EB)
                .append("参加考试（推荐火狐），且需要同意授权共享【整个屏幕】。否则将无法参加考试。")
                .create();
        QJCheckBox cb_cb = findViewById(R.id.cb_cb);
        cb_cb.setOnCheckedChangeListener(new QJCheckBox.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(QJCheckBox var1, boolean var2) {
                findViewById(R.id.rg_auth).setVisibility(var2 ? View.VISIBLE : View.GONE);
            }
        });
        ((QJItemTitleView) findViewById(R.id.itv_toggle_screen)).setOnCheckedChangeListener(new QJItemTitleView.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(QJItemTitleView titleView, QJItemTitleView.Style style, boolean isChecked) {
                findViewById(R.id.ll_toggle_screen).setVisibility(isChecked ? View.VISIBLE : View.GONE);
            }
        });
        ((QJItemTitleView) findViewById(R.id.itv_online_invigilation)).setOnCheckedChangeListener(new QJItemTitleView.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(QJItemTitleView titleView, QJItemTitleView.Style style, boolean isChecked) {
                findViewById(R.id.ll_online_invigilation).setVisibility(isChecked ? View.VISIBLE : View.GONE);
            }
        });
        findViewById(R.id.iv_s_sum).setOnClickListener(this);
        findViewById(R.id.iv_s_add).setOnClickListener(this);
        findViewById(R.id.itv_draw_exam).setOnClickListener(this);
        findViewById(R.id.itv_answer_announced).setOnClickListener(this);
        findViewById(R.id.itv_results_announced).setOnClickListener(this);
        findViewById(R.id.itv_multiple_selection).setOnClickListener(this);
        findViewById(R.id.itv_fill_blanks).setOnClickListener(this);
        findViewById(R.id.itv_sequence).setOnClickListener(this);
        findViewById(R.id.itv_option).setOnClickListener(this);
        findViewById(R.id.itv_answer_questions).setOnClickListener(this);
        findViewById(R.id.iv_sf_toast).setOnClickListener(this);
        findViewById(R.id.iv_sj_toast).setOnClickListener(this);
        findViewById(R.id.iv_qh_toast).setOnClickListener(this);
        findViewById(R.id.iv_jt_toast).setOnClickListener(this);


    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.itv_draw_exam:
                DrawExamAct.start();
                break;
            case R.id.iv_s_sum:
                sNum -= 1;
                if (sNum < 1) {
                    sNum = 1;
                }
                tv_s_num.setText(String.valueOf(sNum));
                break;
            case R.id.iv_s_add:
                sNum += 1;
                tv_s_num.setText(String.valueOf(sNum));
                break;
            case R.id.itv_fill_blanks:
                new SheetDialog(this)
                        .addSheet(new SheetDialog.Sheet("与答案不全匹配时，自动0分", 0, 0))
                        .addSheet(new SheetDialog.Sheet("与答案不全匹配时，手动批改", 0, 1))
                        .addSheet(new SheetDialog.Sheet("与答案不全匹配时，机器自动批改", 0, 2))
                        .setSheetListener(new SheetDialog.SheetListener() {
                            @Override
                            public void sheet(SheetDialog.Sheet sheet) {
                                QJItemTitleView itv = (QJItemTitleView) view;
                                TextView tv = (TextView) ((ViewGroup) itv.getContentView().getChildAt(0)).getChildAt(0);
                                tv.setText(sheet.txt);
                            }
                        }).show();
                break;
            case R.id.itv_multiple_selection:
                new SheetDialog(this)
                        .addSheet(new SheetDialog.Sheet("少选时，得一半分数", 0, 0))
                        .addSheet(new SheetDialog.Sheet("少选、多选、错选不得分", 0, 1))
                        .addSheet(new SheetDialog.Sheet("少选时，按照选项个数得分", 0, 2))
                        .setSheetListener(new SheetDialog.SheetListener() {
                            @Override
                            public void sheet(SheetDialog.Sheet sheet) {
                                QJItemTitleView itv = (QJItemTitleView) view;
                                TextView tv = (TextView) ((ViewGroup) itv.getContentView().getChildAt(0)).getChildAt(0);
                                tv.setText(sheet.txt);
                            }
                        }).show();
                break;
            case R.id.itv_results_announced:
                new SheetDialog(this)
                        .addSheet(new SheetDialog.Sheet("不公布", 0, 0))
                        .addSheet(new SheetDialog.Sheet("定时公布", 0, 1))
                        .addSheet(new SheetDialog.Sheet("学生交卷后公布", 0, 2))
                        .addSheet(new SheetDialog.Sheet("到截止日期公布", 0, 3))
                        .addSheet(new SheetDialog.Sheet("批阅后自动公布", 0, 4))
                        .setSheetListener(new SheetDialog.SheetListener() {
                            @Override
                            public void sheet(SheetDialog.Sheet sheet) {
                                QJItemTitleView itv = (QJItemTitleView) view;
                                TextView tv = (TextView) ((ViewGroup) itv.getContentView().getChildAt(0)).getChildAt(0);
                                tv.setText(sheet.txt);
                                if (sheet.action == 1) {
                                    new AnnouncedTimeDialog(ExamSettingAct.this)
                                            .show();
                                }
                            }
                        }).show();
                break;
            case R.id.itv_answer_announced:
                new SheetDialog(this)
                        .addSheet(new SheetDialog.Sheet("不公布", 0, 0))
                        .addSheet(new SheetDialog.Sheet("定时公布", 0, 1))
                        .addSheet(new SheetDialog.Sheet("学生交卷后公布", 0, 2))
                        .addSheet(new SheetDialog.Sheet("到截止日期公布", 0, 3))
                        .setSheetListener(new SheetDialog.SheetListener() {
                            @Override
                            public void sheet(SheetDialog.Sheet sheet) {
                                QJItemTitleView itv = (QJItemTitleView) view;
                                TextView tv = (TextView) ((ViewGroup) itv.getContentView().getChildAt(0)).getChildAt(0);
                                tv.setText(sheet.txt);
                                if (sheet.action == 1) {
                                    new AnnouncedTimeDialog(ExamSettingAct.this)
                                            .show();
                                }
                            }
                        }).show();
                break;
            case R.id.itv_sequence:
                new SheetDialog(this)
                        .addSheet(new SheetDialog.Sheet("不随机", 0, 0))
                        .addSheet(new SheetDialog.Sheet("全部题目顺序随机", 0, 1))
                        .addSheet(new SheetDialog.Sheet("同一题型顺序随机", 0, 2))
                        .setSheetListener(new SheetDialog.SheetListener() {
                            @Override
                            public void sheet(SheetDialog.Sheet sheet) {
                                QJItemTitleView itv = (QJItemTitleView) view;
                                TextView tv = (TextView) ((ViewGroup) itv.getContentView().getChildAt(0)).getChildAt(0);
                                tv.setText(sheet.txt);
                            }
                        }).show();
                break;
            case R.id.itv_option:
                new SheetDialog(this)
                        .addSheet(new SheetDialog.Sheet("不随机", 0, 0))
                        .addSheet(new SheetDialog.Sheet("随机", 0, 1))
                        .setSheetListener(new SheetDialog.SheetListener() {
                            @Override
                            public void sheet(SheetDialog.Sheet sheet) {
                                QJItemTitleView itv = (QJItemTitleView) view;
                                TextView tv = (TextView) ((ViewGroup) itv.getContentView().getChildAt(0)).getChildAt(0);
                                tv.setText(sheet.txt);
                            }
                        }).show();
                break;
            case R.id.itv_answer_questions:
                new SheetDialog(this)
                        .addSheet(new SheetDialog.Sheet("卡片式", 0, 0))
                        .addSheet(new SheetDialog.Sheet("一页式", 0, 1))
                        .setSheetListener(new SheetDialog.SheetListener() {
                            @Override
                            public void sheet(SheetDialog.Sheet sheet) {
                                QJItemTitleView itv = (QJItemTitleView) view;
                                TextView tv = (TextView) ((ViewGroup) itv.getContentView().getChildAt(0)).getChildAt(0);
                                tv.setText(sheet.txt);
                            }
                        }).show();
                break;
            case  R.id.iv_sf_toast:
                ToastUtil.showTitleToast("学生身份认证","考试前，学生需要上传身份证件照，并完成面部拍照，以便核实是否为本人参加考试。");
                break;
            case  R.id.iv_sj_toast:
                ToastUtil.showTitleToast("面部随机拍照","考试中，系统会对已开启摄像头的学生进行随机拍照，老师可在监考系统中查看。");
                break;
            case R.id.iv_qh_toast:
                ToastUtil.showTitleToast("页面切换检测","考试中，若学生在浏览器中切换标签页或在手机APP端切出、开多窗口等。行为都将被记录且系统自动标记考试异常");
                break;
            case R.id.iv_jt_toast:
                ToastUtil.showTitleToast("电脑桌面截屏","考试中，系统会对已授权共享桌面的学生进行截屏，老师可在监考系统中查看。");
                break;
        }
    }

    @Override
    public void initData(Bundle savedInstanceState) {

    }

    @Override
    public LoadProgressDialog getLoadDialog() {
        return null;
    }

    @Override
    public void cancelLoadDialog() {

    }
}
